<template>
  <div class="order">
     <van-nav-bar
  title="填写订单"
  left-text="返回"
  left-arrow
  @click-left="onClickLeft"
/>

<van-overlay :show="show" @click="show = false">
  <div class="wrapper" @click.stop>
    <div class="block" >
      <p style="font-size:20">提示</p>
      <p>当前暂无收货地址，请先填写收货地址</p>
      <van-divider />
      <p class="enter" @click='displayBlock'>确定</p>
    </div>
  </div>
</van-overlay>

<van-contact-card type="add" @click="onAdd" v-if=change />

<div class="addressList" v-if=addList>
  <div v-for="item in localAddress" :key="item.areaCode">
    <h3>{{item.name}}</h3>
  <p>{{item.tel}}</p>
  <p>{{item.province}}</p>
  <p>{{item.city+item.county+item.addressDetail}}</p>
  </div>
</div>

<van-card
v-for="item in cart"
:key="item.id"
  :num="item.amount"
  tag="包邮"
  :price="item.price"
  :title="item.title"
  :thumb="item.image"
/>
<van-submit-bar :price="totalMoney" button-text="提交订单" @submit="onSubmit" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'order',
  data() {
    return {
      change: '',
      show: '',
      addList: '',
      localAddress: [],
    }
  },
  created() {
    console.log(JSON.parse(localStorage.getItem('address')))
    if (JSON.parse(localStorage.getItem('address'))) {
      this.show = false
      this.change = false
      this.addList = true
      this.localAddress = JSON.parse(localStorage.getItem('address'))
    } else {
      this.show = true
      this.change = true
      this.addList = false
    }
    console.log(this.show)
  },
  computed: {
    ...mapGetters('cart', ['allChecked', 'totalMoney']),
    cart() {
      return this.$store.state.cart.list
    },
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    displayBlock() {
      this.show = false
    },
    onAdd() {
      this.$router.push('/address')
    },
    onSubmit() {
      console.log(this.show)
      if (JSON.parse(localStorage.getItem('address'))) {
        alert('快递已下单，预计3-5天送达')
      } else {
        alert('还没有添加地址哦')
      }
    },
  },
}
</script>

<style lang="less" scoped>
 .wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .block {
    width: 630px;
    height: 240px;
    background-color: #fff;
    text-align: center;
    border-radius: 20px;
    .enter{
     font-size: 16px;
    }
  }
  .addressList{
    width: 699px;
    min-height: 300px;
    background-color: white;
    text-align: center;
  }
</style>
